package cn.coisini.controller.v1;

import cn.coisini.api.admin.CategoryControllerApi;
import cn.coisini.model.common.annotation.RedisAccessLimit;
import cn.coisini.model.common.dtos.Result;
import cn.coisini.model.common.enums.ResultEnum;
import cn.coisini.model.common.log.annotation.Log;
import cn.coisini.model.common.log.enums.BusinessType;
import cn.coisini.model.dto.CategoryDto;
import cn.coisini.model.pojo.Category;
import cn.coisini.model.vo.CategoryVo;
import cn.coisini.model.vo.QueryVo;
import cn.coisini.service.CategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xiangshaw
 * Description: 分类 控制层
 */
@RestController
@RequiredArgsConstructor
public class CategoryController implements CategoryControllerApi {

    private final CategoryService categoryService;

    // 新增分类
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "分类管理", businessType = BusinessType.INSERT)
    public Result<ResultEnum> addCategory(CategoryDto categoryDto) {
        return categoryService.addCategory(categoryDto);
    }

    // 查询分类列表
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    public Result<Object> getCategoryList(QueryVo queryVo) {
        return categoryService.getCategoryList(queryVo);
    }

    // 查询文章分类列表
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    public Result<List<Category>> getArticleCategoryList() {
        return categoryService.getArticleCategoryList();
    }

    // 修改分类
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "分类管理", businessType = BusinessType.STATUS)
    public Result<ResultEnum> updateCategory(CategoryDto categoryDto) {
        return categoryService.updateCategory(categoryDto);
    }

    // 删除分类
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "分类管理", businessType = BusinessType.DELETE)
    public Result<ResultEnum> deleteCategory(CategoryVo categoryVo) {
        return categoryService.deleteCategory(categoryVo.getId());
    }

    // 批量删除分类
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "分类管理", businessType = BusinessType.BATCH_REMOVE)
    public Result<ResultEnum> deleteCategoryByIds(CategoryVo categoryVo) {
        return categoryService.deleteCategoryByIds(categoryVo.getIds());
    }
}
